<template>
  <div class="quality">
    <div class="text">维修质量</div>
    <div class="form">
      <el-form
        :inline="true"
        class="demo-form-inline"
        style="text-align: left"
        label-position="labelPosition"
      >
        <div class="form-top">
          <!-- 时间 -->
          <el-form-item label="开始时间">
            <el-col :span="11" style="width: 300px; padding: 0">
              <el-date-picker
                type="date"
                placeholder="选择日期"
                v-model="form.date1"
                style="width: 100%"
              ></el-date-picker>
            </el-col>
          </el-form-item>
          <el-form-item label="结束时间">
            <el-col :span="11" style="width: 300px; padding: 0">
              <el-date-picker
                type="date"
                placeholder="选择日期"
                v-model="form.date2"
                style="width: 100%"
              ></el-date-picker>
            </el-col>
          </el-form-item>
          <div style="width: 300px; display: flex">
            <el-form-item>
              <el-button
                type="primary"
                icon="el-icon-zoom-in"
                size="mediu"
                @click="onSearch"
                style="margin-left: 20px"
                >查询</el-button
              >
            </el-form-item>
            <el-form-item>
              <el-button
                type="info"
                icon="el-icon-refresh-right"
                size="mediu"
                @click="onRest"
                >重置</el-button
              >
            </el-form-item>
          </div>
        </div>
        <div class="form-bot">
          <!-- 搜索 -->
          <el-form-item label="搜索内容">
            <el-input
              v-model="search"
              placeholder="请输入维修单号"
              style="width: 300px"
            ></el-input>
          </el-form-item>
          <div style="width: 360px"></div>
          <div style="width: 300px"></div>
        </div>
      </el-form>
    </div>
    <!-- 表单数据 -->
    <el-table
      ref="multipleTable"
      :data="tableData"
      tooltip-effect="dark"
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column prop="id" label="维修单号" width="120" align="center">
      </el-table-column>
      <el-table-column
        prop="equipment.equipmentName"
        label="装备名称"
        show-overflow-tooltip
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="equipmentNumber"
        label="装备编号"
        show-overflow-tooltip
        align="center"
      >
      </el-table-column>
      <el-table-column
        label="开始日期"
        width="120"
        align="center"
        prop="startTime"
      >
        <template slot-scope="scope">{{
          switchDate(scope.row.startTime)
        }}</template>
      </el-table-column>

      <el-table-column
        label="结束日期"
        width="120"
        align="center"
        prop="endTime"
      >
        <template slot-scope="scope">{{
          switchDate(scope.row.endTime)
        }}</template>
      </el-table-column>

      <el-table-column
        prop="testStatus"
        label="检测状态"
        show-overflow-tooltip
        align="center"
      >
        <template slot-scope="scope">
          <span>{{
            scope.row.testStatus == 1
              ? "检测中"
              : scope.row.testStatus == 2
              ? "待检测"
              : scope.row.testStatus == 3
              ? "检查完成"
              : "---"
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="testResults"
        label="检测结果"
        show-overflow-tooltip
        align="center"
      >
        <template slot-scope="scope">
          <span>{{
            scope.row.testResults == 1
              ? "已解决"
              : scope.row.testResults == 2
              ? "已检测"
              : "---"
          }}</span>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="140" align="center">
        <template slot-scope="scope">
          <el-button
            class="edit_btn"
            type="primary"
            icon="el-icon-edit-outline"
            @click="openEdit(scope.row)"
            size="small"
          >
          </el-button>
          <el-button
            class="del_btn"
            type="primary"
            icon="el-icon-delete"
            @click="delInfo(scope.row.id)"
            size="small"
          >
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 页码 -->
    <div class="pagination">
      <div style="display: flex; align-items: center">
        <span style="font-size: 13px; font-weight: bold"
          >共{{ Math.ceil(total / limit) }}页/{{ total }}条数据</span
        >
        <div class="block">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page.sync="page"
            :page-size="limit"
            layout="prev, pager, next, jumper"
            :total="total"
          >
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data: function () {
    return {
      tableData: [],

      form: {
        date1: "",
        date2: "",
        state: "",
        name: "",
      },
      search: "",
      page: 1,
      limit: 5,
      total: 0,
      labelPosition: "left",
    };
  },
  methods: {
    //渲染
    getData: function () {
      this.$axios({
        url: "/KeepQuality/queryAllKeepQuality",
        method: "post",
        params: {
          page: this.page,
          limit: this.limit,
        },
        data: {
          startTime: this.form.date1,
          endTime: this.form.date2,
          id: this.search,
        },
      }).then(({ data }) => {
        if (data.code == 0) {
          this.tableData = data.data;
          this.total = data.total;
        } else {
          this.$message.error("网络错误！数据加载出错！");
        }
      });
    },
    //搜索
    onSearch: function () {
      this.getData();
    },
    //重置
    onRest: function () {
      this.form.date1 = "";
      this.form.date2 = "";
      this.search = "";
      this.page=1
      this.getData();
    },

    //分页
    toggleSelection(rows) {
      if (rows) {
        rows.forEach((row) => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      this.page = val;
      this.getData();
    },
    //编辑
    openEdit: function (row) {
      sessionStorage.setItem("quality", JSON.stringify(row));
      this.$store.state.xjqVuex.quality = row;
      this.$router.push("/home/Zlxq");
    },
    //时间转换
    switchDate: function (sj) {
      var now = new Date(sj);
      var year = now.getFullYear();
      var month = now.getMonth() + 1;
      var date = now.getDate();
      return year + "-" + month + "-" + date;
    },
    //删除
    delInfo: function (v) {
      this.$axios({
        url: "/KeepQuality/deleteKeepQuality",
        method: "delete",
        params: {
          id: v,
        },
      }).then((data) => {
        if (data.code == 0) {
          this.$message.success("删除成功！");
          this.getData();
        } else {
          this.$message.error("删除失败！请重新删除！");
        }
      });
    },
  },
  mounted: function () {
    this.getData();
  },
};
</script>
<style lang="less" scoped>
.quality {
  padding: 30px;
}
.text {
  font-weight: 700;
  font-style: normal;
  font-size: 24px;
  color: #344563;
  margin-bottom: 20px;
}
.form {
  display: flex;
  flex-direction: column;
}
.form-top {
  display: flex;
  justify-content: space-around;
}
.form-bot {
  display: flex;
  justify-content: space-around;
}
.del_btn {
  font-size: 14px;
  color: #ffc5c5;
  background: #fef3f3;
  border-color: #fef3f3;
}

.edit_btn {
  font-size: 14px;
  color: #5fa4e2;
  background: #eef6fc;
  border-color: #eef6fc;
}

.pagination {
  display: flex;
  margin-top: 50px;
  justify-content: right;
  margin-right: 20px;
}
</style>
